package engine.game.physicalObjects;

import java.awt.geom.Point2D;

/**
 * Abstract class which represent the commons behaviors of the mobile 
 * objects (i.e. balls, snowBloddy, ..)
 * @author LeoJ
 * @Status not finish.
 *
 */
public abstract class MobileObject extends PhysicalObject {
	/* *********************************************************
	 * Attributes
	 * ********************************************************* */
	private static int gravity;//could be something else than an integer 
	//if needed ...
	private static boolean gravityEnable;
	protected int weight;//will be combine with the gravity and speed
	
	//to create the falling motion.
	/* *********************************************************
	 * Instance Methods
	 * ********************************************************* */
	/**
	 * force the position of a MobileObject
	 * 
	 * NOTE : should be use by a majority to create basics action in 
	 * MobileObject extension...
	 * @param x
	 * @param y
	 */
	protected void setPosition(int x, int y){
		_engloberRect.setLocation(x, y);
	}
	/**
	 * move to the given position if possible (due to the 
	 * maxStepMove) otherwise move to the maxStep distance in this
	 * direction
	 * @param x
	 * @param y
	 */
	protected void moveTo(int x, int y){
		int distance = (int)Point2D.distance(_engloberRect.getX(),
				_engloberRect.getY(), x, y);
		if(distance > this.getMaxMove()){
			//calculate the max move :
			int newX = (int) ((this.getMaxMove()*
					(x-_engloberRect.getX()))/distance);
			int newY = (int) ((this.getMaxMove()*
					(y-_engloberRect.getY()))/distance);
			_engloberRect.setLocation(newX, newY);
		}else{
			//easy part : setLocation to (x,y)
			_engloberRect.setLocation(x, y);
		}
	}
	protected void fallMotion(){
		//will calcul the next step if the object is falling
	}
	/**
	 * give the max move that the object could do during one 
	 * evaluation step.
	 * NOTE : in the extension class, the return value should be a 
	 * static final value...
	 * @return value in pixel of the maximum movement for the 
	 * MobilObject
	 */
	protected abstract int getMaxMove();
	
	/* *********************************************************
	 * Static Methods
	 * ********************************************************* */
	/**
	 * change the gravity value for all the MobileObject
	 */
	public static void setGravity(int newgravityValue){
		gravity = newgravityValue;
	}
	/**
	 * set if the gravity is enable or not
	 */
	public static void setGravityUse(boolean useGravityOrNot){
		gravityEnable = useGravityOrNot;
	}
	
	/**
	 * get the height of a MobileObject
	 */
	public int getHeight(){
		return this.getEngloberRect().height;
	}
	
}
